<?php
if(!isset($_POST['val'])||$_POST['val']==''){
	die('You are not allowed to access the pages');
	exit;
}
$keyWord = $_POST['val'];
$uid = $_POST['devid'];


//$sql = 'SELECT 1 FROM `'.ESYPARK_SEARCH_COOKIES.'` WHERE `address` = "'.$keyWord.'"';

$sql = 'UPDATE `'.ESYPARK_SEARCH_COOKIES.'` SET `times` = `times` + 1 WHERE `devid` = "'.$uid.'" AND `address`= "'.$keyWord.'"';

if($dbObj->executeUpdateStat($sql) < 1){
	//$sql = 'DELETE FROM `'.ESYPARK_SEARCH_COOKIES.'` WHERE `vid` = (SELECT `vid` FROM `'.ESYPARK_SEARCH_COOKIES.'` WHERE `devid` ="'.$uid.'" ORDER BY `vid` ASC LIMIT 3,1)';
	//errorEventLog::displaysSQLPhase($sql,PROGRAM_DEBUG);
	//$rs = $dbObj ->executeDeleteStat($sql);
	
	$sql = 'INSERT INTO `'.ESYPARK_SEARCH_COOKIES.'`(`address`,`devid`) VALUES("'.$keyWord.'","'.$uid.'")';
	$rs = $dbObj -> executeInsertStat($sql);
	
}else{
	echo 'No Records Need To Be Inserted ..';
}